#include "actionwait.h"

ActionWait::ActionWait()
{
    classname = __FUNCTION__;
    actParam = QJsonObject();
}

void ActionWait::setWaitMs(int ms)
{
    actParam.insert("wait",ms);
}

void ActionWait::setBackAction(IAction *act)
{
    actParam.insert("back",
                    QString::number((uintptr_t)act));
}

ActionWait::ActionWait(int ms ,IAction* act)
{
    classname = __FUNCTION__;
    actParam = QJsonObject();
    actParam.insert("wait",ms);
    actParam.insert("back",
                    QString::number((uintptr_t)act));
}

ExecuteRet ActionWait::execute()
{
    int ms = actParam.value("wait").toInt();
    IAction* back = (IAction*) (uintptr_t) (actParam.value(
                "back").toString().toLongLong());
    qInfo()<<classname<<"wait"<<ms<<"ms"<<"back:"<<
             (back?(back->name()):QString("none"));
    if(ms>0)
    {
        QThread::msleep(ms);
    }
    if(back)
    {
        this->setNext(back,1);
        return ERSub1;
    }

    return ERSucc;
}
